define(function (require, exports, module) {
    require('jtemplate');
    require('jdialog');
    require("ajaxproxy");
    require("JTemplate");
    require("layer");

    common = require('common');

    exports.init = function () {

      //查看弹窗
        $(".js-remind-details").on("click","",function(){
            var id = $(this).attr("data-id");
            common.ajaxHandle({
                url:'getRemindById?id=' + $(this).parents('tr').attr('data-id'),
                data:{id:id},
                callback:function(item){
                    console.log(item.data);
                    var temp = JTemplate.render("remind-details",item.data);
                    layer.open({
                        type:1,
                        title:"详情",
                        area: ['560px', '500px'],
                        content:temp

                    })
                }
            });

        });
        $(".js-remind-retransmission").on("click","",function(){
            var id = $(this).attr("data-id");
            common.ajaxHandle({
                url:'do_retransmission?id=' + $(this).parents('tr').attr('data-id'),
                data:{id:id},
                callback:function(data){
                    if ( data.code == "000" ) {
                        JDialog.tip.work({type:"ok", content:data.message, lock:true, timer:500,callback:function(){location.reload();}});
                        //location.reload();
                    } else {
                        JDialog.tip.work({type:"error", content:data.message, timer:500});
                    }


                }
            });

        });
        $(".css-switch input").on("change",function(){
            var id = $(this).attr('data-id');
            var value = $(this).is(":checked") ?  'on' : 0;
            $.post('do_editTmpl',{id:id,data:{status : value}},function(data){
                if ( data.code == "000" ) {
                    JDialog.tip.work({type:"ok", content:data.message, lock:true, timer:500});
                } else {
                    JDialog.tip.work({type:"error", content:data.message, timer:1500,callback:function() {location.reload();}  });

                }
            },'json');

        });



    };


    exports.initByRule = function () {


        $(".css-switch input").on("change",function(){
            var id = $(this).attr('data-id');
            var value = $(this).is(":checked") ?  'on' : 0;
            $.post('do_editRule',{id:id,data:{status : value}},function(data){
                if ( data.code == "000" ) {
                    JDialog.tip.work({type:"ok", content:data.message, lock:true, timer:500});
                } else {
                    JDialog.tip.work({type:"error", content:data.message, timer:1500,callback:function() {location.reload();}  });

                }
            },'json');

        });

    };
});
